package com.soft.javase.day08.removeduplicate;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/27
 */
public class PersonRemoveDuplicate {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("张三",23));
        personList.add(new Person("李四",24));
        personList.add(new Person("张三",23));
        personList.add(new Person("王五",22));
        personList.add(new Person("李四",24));

        System.out.println("去重前的person列表: " + personList);

        List<Person> removedList = removeDuplicate(personList);

        System.out.println("去重后的person列表: " + removedList);
    }

    public static List<Person> removeDuplicate(List<Person> list) {
        List<Person> result = new ArrayList<>();
        for (Person item : list) {
            if (!result.contains(item)) {
                result.add(item);
            }
        }
        return result;
    }
}
